//
//  Stalaktit.m
//  MessangerSkeleton
//
//  Created by User-23 on 4/27/14.
//  Copyright (c) 2014 IOTrainingCamp. All rights reserved.
//

#import "Stalaktit.h"
#import "cocos2d.h"
#import "Configuration.h"

@interface Stalaktit ()

@property GameObjectType* type;
@end

@implementation Stalaktit

- (instancetype)init
{
    self = [super initWithSpriteFrame:[CCSpriteFrame frameWithImageNamed:@"bee.png"]];
    if (self) {
        
        self.type = kObstacleHigh;
        
        //TODO: should be loaded from a plist and this should be separate method common for all sprites
        int num = 5;
        CGPoint* bee = malloc(sizeof(CGPoint)*num);
        bee[0] = ccp(194.8f, 142.9f);
        bee[1] = ccp(-190.7f, 162.8f);
        bee[2] = ccp(-189.2f, -6.3f);
        bee[3] = ccp(-24.9f, -160.8f);
        bee[4] = ccp(148.7f, -21.2f);

        
        CGPoint offset = ccp(190.7f, 160.8);
        
        for(int i=0; i< num; i++)
        {
            bee[i] = ccp(bee[i].x + offset.x, bee[i].y + offset.y);
        }
        
        
        self.physicsBody = [CCPhysicsBody bodyWithPolygonFromPoints:bee count:num cornerRadius:20];
        
        free(bee);
        self.scale = 0.3;
        self.physicsBody.sensor = YES;
        self.physicsBody.collisionType = @"obstacle";
    }
    return self;
}

-(void)update:(CCTime)delta
{
    if(self.position.x + self.boundingBox.size.width < 0)
        [self removeFromParentAndCleanup:YES];
}

@end
